//ajax
    $("#tbl_user").bootstrapTable({
        url:"chushou/getthId",
        method:'post',
        toolbar:'#toolbar',
        contentType:'application/x-www-form-urlencoded',
        sidePagination:'server',
        pageNumber:1,
        pageSize:5,
        queryParams:function(params){
            params["id"] = $("#cs_id").val();
            return params;
        },
        pageList:[5, 25, 50, 100,'ALL'],
        dataType:'json',
        cache:false,
        pagination:true,

        showRefresh:true,
        showColumns:true,
        classes:'table table-hover table-striped',
        columns: [{
            title:"序号",
            align:"center",
            formatter:function(value,row,index){
                if(row.dd_tuihui != 0){
                    return "<span style='color: red'>已退回</span>";
                }
                return (index + 1);
            }
        },{
            field:"ts_id.tu_name",
            title:"图书名称",
            align:"center"
        },{
            field:"ts_id.jieyue",
            title:"借阅价格",
            align:"center"
        },{
            field:"ts_id.chushou",
            title:"出售价格",
            align:"center"
        },{
            field:"ts_id.posun",
            title:"破损量比",
            align:"center"
        },{
            field:"ts_id.cishu",
            title:"借阅次数",
            align:"center"
        },{
            field:"ts_id.lx.lx_name",
            title:"类型",
            align:"center"
        },{
            field:"ts_id.chubanshe.cbs_name",
            title:"出版社名字",
            align:"center"
        },{
            field:"ts_id.book_img",
            title:"图书图片",
            align:"center",
            formatter:function (value, row, index) {
                return '<img src="'+row.ts_id.book_img+'" width="80px" />';
            }
        },{
            title:"操作",
            align:"center",
            formatter:function (value, row, index) {
                var html = [
                    "<a href='javascript:void(0);' onclick='delRow("+row.id+","+row.dd_tuihui+")'style='color: red'>退回</a>",
                ];
                return html.join("");
            }
        }]
    });

$("#cs_id").change(function (){
    var id=$(this).val();
    $.ajax({
        url:'chushou/getId',
        method:"post",
        data:{"id":id},
        dataType:"json",
        success:function (data) {
           if(data != null){
               $("#cs_name").val(data.cs_name);
               $("#cs_shouji").val(data.cs_shouji);
               $("#cs_shenfen").val(data.cs_shenfen);
               $("#cs_dizhi").val(data.cs_dizhi);
               $("#cs_jine").val(data.cs_jine);
               $("#cs_riqi").val(data.cs_riqi);
               $("#tbl_user").bootstrapTable('refresh');
           }

        }
    });
})

//删除一行数据
function delRow(row,tuihui) {
    var shijian = new Date();
    var a = shijian.toLocaleDateString();
    var b = $("#cs_riqi").val().substr(0,10);

    var dangqian =  new Date(a);
    var shuju =  new Date(b);
    var cha = Math.ceil((dangqian - shuju) / (1000 * 60 * 60 * 24));

    if(cha < 3){
        if(tuihui != 0){
            swal("错误！", "您已经退回这本书", "error");
        }else{
            swal({
                title: "您确定要删除这条信息吗",
                text: "删除后将无法恢复，请谨慎操作！",
                type: "warning",
                showCancelButton: true,
                cancelButtonText: "我再想想吧!",
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "删除",
                closeOnConfirm: false
            }, function () {
                $.ajax({
                    url:'chushou/delBy',
                    method:"post",
                    data:{"id":row},
                    success:function (data) {
                        swal("退回成功！", "您已经永久修改了这条信息。", "success");
                        //刷新表格
                        $("#tbl_user").bootstrapTable('refresh');
                    }
                });
            });
        }
    }else{
        swal("错误！", "不可退回已超过三天。", "error");
    }
}

//提交表单
function submitForm(btn) {
    $("#cs_jine").removeAttr("disabled");
    var $form = $(btn).parents("#modal1").find("#myForm");
    $($form).find("#dz_shenFen").removeAttr("disabled");
    var action = $form.attr("action");
    var str = $form.serialize();
    $.ajax({
        url:action,
        method:"post",
        //data:str,
        //FormData(dom)
        data:str,
        dataType:'json',
        // processData: false,
        // contentType: false,
        success:function (data) {
            if(data.result){
                swal("成功", "操作成功", "success");
                //隐藏模态框
                $("#modal1").modal('hide');
                //刷新表格
                $("#tbl_user").bootstrapTable('refresh');

            }
        }
    });
}
